﻿using Heima.OA.Common;
using Heima.OA.IBLL;
using Heima.OA.Model;
using Heima.OA.UI.Portal.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Heima.OA.UI.Portal.Areas.Check.Controllers
{
    public class AuditController : BaseController
    {
        public IZS_AuditService ZS_AuditService { get; set; }
        // GET: Check/Audit
        public string Index(PaginationQuery paginationQuery)
        {
            int total = 0;
            var auditList = ZS_AuditService.GetPageEntities(paginationQuery.pagesize, paginationQuery.pageindex, out total, u => u.DelFlag == delflagNormal,
                s => s.CreateTime, true);

            PaginationData data = new PaginationData() { total = total, rows = JsonHandler.ToJson(auditList) };
            JsonMessage msg = JsonHandler.CreateMessage((int)MsgTypeEnum.成功, "", JsonHandler.ToJson(data));

            return JsonHandler.ToJson(msg);
        }

        #region 添加
        public string Create(ZS_Audit audit)
        {
            audit.DelFlag = delflagNormal;
            audit.CreateTime = DateTime.Now;
            audit.AuditOneTime = DateTime.Now;
            audit.AuditOnePerson = LoginUser.UName;
            audit.AuditOneState = (short)AllEnum.AuditOneStateEnum.审核通过;

            ZS_AuditService.Add(audit);
            JsonMessage message = JsonHandler.CreateMessage((int)MsgTypeEnum.成功, "添加成功!");
            return JsonHandler.ToJson(message);
        }

        #endregion
        #region 二审
        public string AuditTwo(ZS_Audit audit)
        {
            JsonMessage msg = new JsonMessage();
            ZS_Audit auditModel = ZS_AuditService.GetModel(audit.Id);
            if(auditModel != null)
            {
                auditModel.AuditTwoPerson = LoginUser.UName;
                auditModel.AuditTwoTime = DateTime.Now;
                ZS_AuditService.Update(auditModel);
                msg = JsonHandler.CreateMessage((int)MsgTypeEnum.成功, "审核成功!");
            }
            else
            {
                msg = JsonHandler.CreateMessage((int)MsgTypeEnum.错误, "审核错误!");
            }
            return JsonHandler.ToJson(msg);
        }
        #endregion
        #region 三审
        public string AuditThree(ZS_Audit audit)
        {
            JsonMessage msg = new JsonMessage();
            ZS_Audit auditModel = ZS_AuditService.GetModel(audit.Id);
            if (auditModel != null)
            {
                auditModel.AuditThreePerson = LoginUser.UName;
                auditModel.AuditThreeTime = DateTime.Now;
                ZS_AuditService.Update(auditModel);
                msg = JsonHandler.CreateMessage((int)MsgTypeEnum.成功, "审核成功!");
            }
            else
            {
                msg = JsonHandler.CreateMessage((int)MsgTypeEnum.错误, "审核错误!");
            }
            return JsonHandler.ToJson(msg);
        }
        #endregion

    }
}